<?php


	//判断post是否有值
	if(!empty($_POST)){
			//获取用户名和密码
			$username=$_POST['username'];
			// $code=$_POST['code'];
			// $code1=$_SESSION['code'];
			// if(strtolower($code)!=strtolower($code1)){
			// 	echo '<script>alert("验证码错误");history.go(-1);</script>';die;
			// }
			//md5加密
			$password=md5($_POST['password']);
			//判断判断cookie是否为空
			if(!empty($_COOKIE['password'])){
				//判断post过来的值是否和cookie保存的密码相同
				if($_POST['password']==$_COOKIE['password']){
					//相同则将把cookie赋值给密码变量
					$password=$_COOKIE['password'];
				}
			}
			//获取用户名和密码
			$username=$_POST['username'];
			//md5加密
			$password= md5($_POST['password']);
			//判断判断cookie是否为空
			if(!empty($_COOKIE['password'])){
				//判断post过来的值是否和cookie保存的密码相同
				if($_POST['password']==$_COOKIE['password']){
					//相同则将把cookie赋值给密码变量
					$password=$_COOKIE['password'];
				}
			}
					$where['username']=$username;
					$where['password']=$password;
					$is_tabs['admin.role_id']='role.id';
					$field='admin.*,role.power';
					$data =getSelectOne('admin,role',$where,$field,$is_tabs);
	//select admin.*,role.power from admin,role where  username = 'admin' and password = '202cb962ac59075b964b07152d234b70' and admin.role_id=role.id

					if(!empty($data)){
						//权限验证
						//if(!empty($_SESSION['power'])){
							$_SESSION['power']=explode(',',$data['power']);
						//}

						//把数据保存到session里面
						$_SESSION['admin']=$data;
						//判断是否勾选记住我
						if(!empty($_POST['check'])){
							setcookie('username',$username,time()+3600*24);
							setcookie('password',$password,time()+3600*24);
						}
						else{
							setcookie('username','',0);
							setcookie('password','',0);
						}
						if(!empty($_POST['auto_login'])){
							setcookie('auto_login',1,time()+3600*24);
						}else{
							setcookie('auto_login','',0);
						}
						//echo '<script>location.href="index.html"</script>';
						header('location:index.php?c=index&a=index&admin=1');
					//}
			}else{
				echo '<script>alert("用户名或密码错误，请重试");history.go(-1);</script>';
			}

	}
	include (VIEW_PATH.$admin.'admin/login.html');
?>

